//
//  LayoutAd1View.m
//  Menu
//
//  Created by trimad on 11-12-9.
//  Copyright 2011 Trimad Group. All rights reserved.
//

#import "LayoutAd1View.h"
#import "Item.h"

@implementation LayoutAd1View

@synthesize bgImageView;
@synthesize videoFrameView;

MPMoviePlayerController *videoPlayer;

- (id)initWithFrameAndItems:(CGRect)frame items:(NSArray *) items {
	self = [super initWithFrameAndItems:frame items:items];
	Item *item = [items objectAtIndex:0];
	NSString *bgImageString = [item.adImageArray objectAtIndex:0];
	bgImageView.image = [UIImage imageNamed:bgImageString];
	
	NSString *url = [item.adVideoUrlArray objectAtIndex:0];
	videoPlayer = [[MPMoviePlayerController alloc] 
				   initWithContentURL:[NSURL fileURLWithPath:url]];
	CGSize videoSize;
	videoSize.width = videoFrameView.frame.size.width - 10;
	videoSize.height = videoFrameView.frame.size.height - 10;
	videoPlayer.view.frame = CGRectMake(5, 5, videoSize.width, videoSize.height);
	videoPlayer.shouldAutoplay = NO;
	[videoPlayer pause];
	[videoFrameView addSubview: videoPlayer.view];
	
	return self;
}

- (void)activate: (Item *) item {
	NSString *bgImageString = [item.adImageArray objectAtIndex:0];
	bgImageView.image = [UIImage imageNamed:bgImageString];
	
	NSString *url = [item.adVideoUrlArray objectAtIndex:0];
	videoPlayer = [[MPMoviePlayerController alloc] 
				   initWithContentURL:[NSURL fileURLWithPath:url]];
	CGSize videoSize;
	videoSize.width = videoFrameView.frame.size.width - 10;
	videoSize.height = videoFrameView.frame.size.height - 10;
	videoPlayer.view.frame = CGRectMake(5, 5, videoSize.width, videoSize.height);
	videoPlayer.shouldAutoplay = NO;
	[videoPlayer pause];
	[videoFrameView addSubview: videoPlayer.view];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code.
}
*/

- (void)dealloc {
	[bgImageView release];
	[videoFrameView release];
    [super dealloc];
}


@end
